import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/view/login.vue'
import Home from '@/view/home.vue'
import Wellcome from '@/components/wellcome.vue'
import Test2 from '@/components/test2.vue'
import Test3 from '@/components/test3.vue'
import Test4 from '@/components/test4.vue'
import Test5 from '@/components/test5.vue'
import Test6 from '@/components/test6.vue'
import Test7 from '@/components/test7.vue'
import Warning from '@/components/warning.vue'
import DeviceConf from '@/components/deviceConf.vue'
import DeviceTypeConf from '@/components/deviceTypeConf.vue'
// 引入加载条
// import NProgress from 'nprogress'
// import 'nprogress/nprogress.css'
// 配置
// NProgress.inc()
// NProgress.configure({
//   easing: 'ease', // 动画方式
//   speed: 800, // 递增进度条的速度
//   showSpinner: false, // 是否显示加载ico
//   trickleSpeed: 200, // 自动递增间隔
//   minimum: 0.1 // 初始化时的最小百分比
// })

Vue.use(VueRouter)

const router = new VueRouter({
  mode: "history", //路由模式
  base: "/web/", //部署的子路径

  routes: [{
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },

    //访问home时，重定向到wellcome页
    {
      path: '/home',
      name: 'home',
      component: Home,
      redirect: '/wellcome',
      meta: {
        title: '控制台'
      },
      children: [{
          path: '/wellcome',
          name: 'wellcome',
          component: Wellcome,
          meta: {
            title: '控制台'
          }
        },


        {
          path: '/test2',
          name: 'test2',
          component: Test2,
          meta: {
            title: '设备管理'
          }
        },
        {
          path: '/test3',
          name: 'test3',
          component: Test3,
          meta: {
            title: '用户管理'
          }
        },
        {
          path: '/test4',
          name: 'test4',
          component: Test4,
          meta: {
            title: '厂房管理'
          }
        },
        {
          path: '/test5',
          name: 'test5',
          component: Test5,
          meta: {
            title: '型号配置'
          }
        },
        {
          path: '/test6',
          name: 'test6',
          component: Test6,
          meta: {
            title: '参数配置'
          }
        },
        {
          path: '/test7',
          name: 'test7',
          component: Test7,
          meta: {
            title: '网关配置'
          }
        },
        {
          path: '/deviceConf',
          name: 'deviceConf',
          component: DeviceConf,
          meta: {
            title: ''
          }
        },
        {
          path: '/deviceTypeConf',
          name: 'deviceTypeConf',
          component: DeviceTypeConf,
          meta: {
            title: ''
          }
        },
        {
          path: '/permissionSetting',
          name: 'permissionSetting',
          component: () => import('@/components/permissionSetting'),
          meta: {
            title: ''
          }
        },
        {
          path: '/warning',
          name: 'warning',
          component: Warning
        }


      ]
    }
  ]
})

/**
 * 挂载路由守卫
 * to 代表将要访问的路径
 * from 代表从哪个路径跳转而来
 * next 是一个函数，next() 放行。   next('/login') 强制跳转
 */
router.beforeEach((to, from, next) => {
  // 加载条
  // NProgress.start()

  //放行
  next()
})


// 挂载路由守卫 - 访问结束
router.afterEach(() => {
  // 关闭加载条
  // NProgress.done()
})

export default router
